using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace FrameWork
{
    [CreateAssetMenu(fileName = "TimeData", menuName = "Data/TimeData")]
    public class TimeDataSO : ScriptableObject
    {
        public int CurrentDay { get; private set; }
        public int CurrentYear { get; private set; }
        public int CurrentSeason { get; private set; }
        public int CurrentHour { get; private set; }
        public int CurrentDayOfWeek { get; private set; }
        
        private event Action<TimeDataSO> updateInfo;              // 玩家数据改变后，更新UI面板

        /// <summary>
        /// 数据初始化
        /// </summary>
        public void Init(int currentDay, int currentYear, int currentSeason, int currentHour, int currentDayOfWeek)
        { 
            this.CurrentDay = currentDay;
            this.CurrentYear = currentYear;
            this.CurrentSeason = currentSeason;
            this.CurrentHour = currentHour;
            this.CurrentDayOfWeek = currentDayOfWeek;
            
            // Debug.Log("时间初始化");
            // UpdateInfo();
        }

        public void Initialize()
        {
            // Debug.Log("时间初始化");
            UpdateInfo();
        }

        /// <summary>
        /// 更新时间
        /// </summary>
        /// <param name="day">日</param>
        /// <param name="year">年</param>
        /// <param name="season">季度</param>
        /// <param name="hour">时间</param>
        /// <param name="dayOfWeek">星期</param>
        public void UpdateTimeData(int day, int year, int season, int hour, int dayOfWeek)
        {
            CurrentSeason = season;
            CurrentYear = year;
            CurrentDay = day;
            CurrentHour = hour;
            CurrentDayOfWeek = dayOfWeek;

            // 通知UI界面更新数据
            // Debug.Log("更新数据" + CurrentHour + CurrentYear);
            UpdateInfo();
        }
        
        //
        public void AddListener(Action<TimeDataSO> action)
        {
            updateInfo += action;
        }
        
        //
        public void RemoveListener(Action<TimeDataSO> action)
        {
            updateInfo -= action;
        }
        
        //
        public void UpdateInfo()
        {
            updateInfo?.Invoke(this);
        }
    }
}
